package com.example.demo.controller;

import com.example.demo.common.Result;
import com.example.demo.entity.Broadcasts;
import com.example.demo.mapper.BroadcastsMapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author sean
 */
@RestController
@RequestMapping("/broadcasts")
public class BroadcastsController extends BaseController {

    @Resource
    BroadcastsMapper broadcastsMapper;

    @PostMapping
    public Result<?> save(@RequestBody Broadcasts broadcasts) {
        broadcasts.setCreateTime(new Date());
        return Result.success(broadcastsMapper.insert(broadcasts));
    }

    @PutMapping
    public Result<?> update(@RequestBody Broadcasts broadcasts) {
        return Result.success(broadcastsMapper.updateById(broadcasts));
    }

    @DeleteMapping("/{id}")
    public Result<?> delete(@PathVariable Long id) {
        return Result.success(broadcastsMapper.deleteById(id));
    }

    @GetMapping("/{id}")
    public Result<?> getById(@PathVariable Long id) {
        return Result.success(broadcastsMapper.selectById(id));
    }

    @GetMapping("/all")
    public Result<?> findAll() {
        return Result.success(broadcastsMapper.selectList(null));
    }

}
